﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.BankAccounts;
using Domain.MainModule.BankAccountTypes;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class BankAccountRepositoryTest : RepositoryTestsBase<BankAccount>
    {
        public override System.Linq.Expressions.Expression<Func<BankAccount, bool>> FilterExpression
        {
            get { return a => a.BankAccountId == TestConstants.Instance.BANK_ACCOUNT_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<BankAccount, Guid>> OrderByExpression
        {
            get { return a => a.BankAccountId; }
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindBankAccount_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBankAccountRepository repository = new BankAccountRepository(context, traceManager);

            //Act
            repository.FindBankAccounts(null);
        }

        [TestMethod()]
        public void FindBankAccount_Invoke_InvalidIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBankAccountRepository repository = new BankAccountRepository(context, traceManager);

            Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            BankAccountUserIdSpecification spec = new BankAccountUserIdSpecification(invalidId);

            //Act
            IEnumerable<BankAccount> bankAccount = repository.FindBankAccounts(spec);

            //Assert
            Assert.AreEqual(0, bankAccount.Count());
        }

        [TestMethod()]
        public void FindBankAccountByUserId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBankAccountRepository repository = new BankAccountRepository(context, traceManager);


            BankAccountUserIdSpecification spec = new BankAccountUserIdSpecification(TestConstants.Instance.USER_ID);

            //Act
            IEnumerable<BankAccount> result = repository.FindBankAccounts(spec);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }

        [TestMethod()]
        public void GetAllBankAccountTypes_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBankAccountTypeRepository repository = new BankAccountTypeRepository(context, traceManager);

            //Act
            IEnumerable<BankAccountType> result = repository.GetAll();

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }
    }
}
